<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Insert title here</title>
<link href="/resource/css/bootstrap.min.css" rel="stylesheet">
<script type="text/javascript" src="/resource/js/jquery-3.2.1.js"></script>
<script type="text/javascript" src="/resource/js/bootstrap.min.js"></script>

<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<script type="text/javascript">
	function goPage(pageNum){
		//location="/list?pageNum="+pageNum;
		$("[name='pageNum']").val(pageNum);
		$("form").submit();
	}
	function add(){
		location="/add";
	}
	function cks(flag){
		if(flag==1){
			$("[name='ck']").prop("checked",true);
		}else if(flag==2){
			$("[name='ck']").prop("checked",false);
		}else{
			$("[name='ck']").each(function(){
				this.checked=!this.checked;
			})
		}
	}
	function dels(){
		var ids=new Array();
		$("[name='ck']:checked").each(function(i){
			ids[i]=$(this).val();
		})
		alert(ids);
		if(ids.length==0){
			alert("请至少选择一个要删除的商铺");
			return;
		}
		var ret=confirm("确定要删除吗");
		if(ret){
			$.post(
					"/dels",
					{ids:ids},
			function(msg){
						if(msg){
							alert("删除成功");
							location="/list";
						}else{
							alert("删除失败");
						}
					}
			
			)
		}
	}
	$.post(
			"/getProducts",
			function(msg){
				for ( var i in msg) {
					$("#d1").append("<input type='checkbox' name='pnames' value='"+msg[i].pid+"'>"+msg[i].pname+"");
				}
			}
	)
</script>
</head>
<body>

	<div>
	<form action="/list" method="post">
	
	<div id="d1">
	销售商品：
	</div>
	店铺名称:<input type="text" name="sname" value="${s.sname }">
	<input type="hidden" name="pageNum">
	<button type="submit">查询</button>
	</form>
	<button type="button" onclick="add()">添加</button>
	<button type="button" onclick="dels()">批量删除</button>
	</div>
	<table class="table">
	<tr>
	<td>
	<button type="button" onclick="cks(1)">全选</button>
	<button type="button" onclick="cks(2)">全不选</button>
	<button type="button" onclick="cks(3)">反选</button>
	</td>
	<td>编号</td>
	<td>店铺名称</td>
	<td>创建日期</td>
	<td>销售商品</td>
	<td>操作</td>
	</tr>
	<c:forEach items="${info.list }" var="shop" varStatus="i">
	<tr>
	<td>
	<input type="checkbox" name="ck" value="${shop.sid }">
	</td>
	<td>${shop.sid }</td>
	<td>${shop.sname }</td>
	<td><fmt:formatDate value="${shop.stime }" pattern="yyyy-MM-dd"/> </td>
	<td>${shop.pnames }</td>
	<td>
	<a href="/show?id=${shop.sid }" target="blank">查看</a>
	<a href="/getOneForUpdate?id=${shop.sid }">修改</a>
	</td>
	</tr>
	
	</c:forEach>
	</table>
	<div>
	<jsp:include page="/WEB-INF/view/pages.jsp"></jsp:include>
	
	</div>
</body>
</html>